1 Podsumowanie analizy

2 Wykorzystane biblioteki

Do stworzenia raportu wykorzystano następujące biblioteki:

library(knitr)
library(dplyr)
library(ggplot2)
library(skimr)
library(plotly)
library(caret)
library(ggeasy)
library(formattable)
library(tidyverse)
library(scales)
library(ggcorrplot)

W celu uzyskania powtarzalności rezultatów ustawiono ziarno dla generatora liczb pseudolosowych.

set.seed(23)

3 Wczytanie danych

Poniżej znajduje się kod odpowiedzialny za wczytanie danych z plików.

inventories <- read.csv("rebrickable/inventories.csv")
inventory_parts <- read.csv("rebrickable/inventory_parts.csv")
parts <- read.csv("rebrickable/parts.csv")
part_categories <- read.csv("rebrickable/part_categories.csv")
part_relationships <- read.csv("rebrickable/part_relationships.csv")
elements <- read.csv("rebrickable/elements.csv")
colors <- read.csv("rebrickable/colors.csv")
inventory_minifigs <- read.csv("rebrickable/inventory_minifigs.csv")
minifigs <- read.csv("rebrickable/minifigs.csv")
inventory_sets <- read.csv("rebrickable/inventory_sets.csv")
sets <- read.csv("rebrickable/sets.csv")
themes <- read.csv("rebrickable/themes.csv")

4 Opis zbioru danych

Cały zbiór danych dotyczący klocków LEGO składa się z 12 tabel. Poniżej znajdują się sekcje zawierające opisy każdej z nich, wyświetlające informacje o ich rozmiarze oraz podstawowe statystyki.

4.1 Inventories

Jest to tabela nadrzędna łącząca części i figurki z zestawami LEGO.
Tabela zawiera 37265 rekordów.

Atrybuty w tej tabeli to:

  • id
  • version - numer wersji
  • set_num - numer zestawu
Podstawowe statystyki danych z tabeli
id version set_num
Min. : 1 Min. : 1.000 Length:37265
1st Qu.: 14424 1st Qu.: 1.000 Class :character
Median : 54379 Median : 1.000 Mode :character
Mean : 61104 Mean : 1.091 NA
3rd Qu.: 88842 3rd Qu.: 1.000 NA
Max. :194312 Max. :16.000 NA
Kilka pierwszych elementów z tabeli
id version set_num
1 1 7922-1
3 1 3931-1
4 1 6942-1
15 1 5158-1
16 1 903-1
17 1 850950-1
Data summary
Name inventories
Number of rows 37265
Number of columns 3
_______________________
Column type frequency:
character 1
numeric 2
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
set_num 0 1 3 20 0 35644 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
id 0 1 61103.60 51380.10 1 14424 54379 88842 194312 ▇▆▂▂▂
version 0 1 1.09 0.58 1 1 1 1 16 ▇▁▁▁▁

4.2 Inventory Parts

W tej tabeli zostały zawarte informacje o zapasach (nakładach) części LEGO.
Tabela zawiera 1180987 rekordów.

Atrybuty w tej tabeli to:

  • inventory_id
  • part_num - oznaczenie części
  • color_id - numer koloru
  • quantity - ilość
  • is_spare - zmienna typu bool, określająca czy część jest zapasowa
  • img_url - adres url zdjęcia części
Podstawowe statystyki danych z tabeli
inventory_id part_num color_id quantity is_spare img_url
Min. : 1 Length:1180987 Min. : -1.0 Min. : 1.00 Length:1180987 Length:1180987
1st Qu.: 9404 Class :character 1st Qu.: 4.0 1st Qu.: 1.00 Class :character Class :character
Median : 22838 Mode :character Median : 15.0 Median : 2.00 Mode :character Mode :character
Mean : 50849 NA Mean : 131.8 Mean : 3.37 NA NA
3rd Qu.: 87088 NA 3rd Qu.: 71.0 3rd Qu.: 4.00 NA NA
Max. :194312 NA Max. :9999.0 Max. :3064.00 NA NA
Kilka pierwszych elementów z tabeli
inventory_id part_num color_id quantity is_spare img_url
1 48379c01 72 1 f https://cdn.rebrickable.com/media/parts/photos/1/48379c01-1-e7daa845-2671-4737-8642-3b1574308155.jpg
1 48395 7 1 f https://cdn.rebrickable.com/media/parts/photos/7/48395-7-b9152acf-2fa5-4836-a04d-5b7fd39c2406.jpg
1 stickerupn0077 9999 1 f
1 upn0342 0 1 f
1 upn0350 25 1 f
3 2343 47 1 f https://cdn.rebrickable.com/media/parts/elements/3000240.jpg
Data summary
Name inventory_parts
Number of rows 1180987
Number of columns 6
_______________________
Column type frequency:
character 3
numeric 3
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
part_num 0 1 1 20 0 51051 0
is_spare 0 1 1 1 0 2 0
img_url 0 1 0 117 8180 74266 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
inventory_id 0 1 50849.46 55136.94 1 9404 22838 87088 194312 ▇▂▁▂▁
color_id 0 1 131.78 862.38 -1 4 15 71 9999 ▇▁▁▁▁
quantity 0 1 3.37 9.95 1 1 2 4 3064 ▇▁▁▁▁

4.3 Parts

Tabela parts zawiera informacje o częściach LEGO, które mogą składać się z kilku elementów.
Tabela zawiera 52615 rekordów.

Atrybuty w tej tabeli to:

  • part_num - oznaczenie części
  • name - nazwa części
  • part_cat_id - id kategorii części
  • part_material - materiał, z którego wykonano część
Podstawowe statystyki danych z tabeli
part_num name part_cat_id part_material
Length:52615 Length:52615 Min. : 1.00 Length:52615
Class :character Class :character 1st Qu.:17.00 Class :character
Mode :character Mode :character Median :41.00 Mode :character
NA NA Mean :38.91 NA
NA NA 3rd Qu.:60.00 NA
NA NA Max. :68.00 NA
Kilka pierwszych elementów z tabeli
part_num name part_cat_id part_material
003381 Sticker Sheet for Set 663-1 58 Plastic
003383 Sticker Sheet for Sets 618-1, 628-2 58 Plastic
003402 Sticker Sheet for Sets 310-3, 311-1, 312-3 58 Plastic
003429 Sticker Sheet for Set 1550-1 58 Plastic
003432 Sticker Sheet for Sets 357-1, 355-1, 940-1 58 Plastic
003434 Sticker Sheet for Set 575-2, 653-1, 460-1 58 Plastic
Data summary
Name parts
Number of rows 52615
Number of columns 4
_______________________
Column type frequency:
character 3
numeric 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
part_num 0 1 1 20 0 52615 0
name 0 1 3 222 0 52103 0
part_material 0 1 4 16 0 7 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
part_cat_id 0 1 38.91 22.08 1 17 41 60 68 ▃▃▂▁▇

4.4 Part Categories

Tabela part_categories zawiera informacje o kategoriach części LEGO.
Tabela zawiera 66 rekordów.

Atrybuty w tej tabeli to:

  • id
  • name - nazwa kategorii części
Podstawowe statystyki danych z tabeli
id name
Min. : 1.00 Length:66
1st Qu.:19.25 Class :character
Median :35.50 Mode :character
Mean :35.36 NA
3rd Qu.:51.75 NA
Max. :68.00 NA
Kilka pierwszych elementów z tabeli
id name
1 Baseplates
3 Bricks Sloped
4 Duplo, Quatro and Primo
5 Bricks Special
6 Bricks Wedged
7 Containers
Data summary
Name part_categories
Number of rows 66
Number of columns 2
_______________________
Column type frequency:
character 1
numeric 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
name 0 1 4 44 0 66 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
id 0 1 35.36 19.41 1 19.25 35.5 51.75 68 ▇▇▇▇▇

4.5 Part Relationships

W tej tabeli zostały zawarte informacje o relacjach między poszczególnymi częściami.
Tabela zawiera 29977 rekordów.

Atrybuty w tej tabeli to:

  • rel_type - oznaczenie relacji
  • child_part_num - oznaczenie części “dziecka”
  • parent_part_num - oznaczenie części “rodzica”
Podstawowe statystyki danych z tabeli
rel_type child_part_num parent_part_num
Length:29977 Length:29977 Length:29977
Class :character Class :character Class :character
Mode :character Mode :character Mode :character
Kilka pierwszych elementów z tabeli
rel_type child_part_num parent_part_num
P 3626cpr3662 3626c
P 87079pr9974 87079
P 3960pr9971 3960
R 98653pr0003 98086pr0003
R 98653pr0003 98088pat0003
R 98653pr0003 98089pat0003
Data summary
Name part_relationships
Number of rows 29977
Number of columns 3
_______________________
Column type frequency:
character 3
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
rel_type 0 1 1 1 0 6 0
child_part_num 0 1 1 20 0 27139 0
parent_part_num 0 1 1 19 0 4725 0

4.6 Elements

W tabeli elements znajdują się informacje o pojedynczych klockach LEGO.
Tabela zawiera 84138 rekordów.

Atrybuty w tej tabeli to:

  • element_id
  • part_num - oznaczenie części, w której skład wchodzi dany element
  • color_id - numer koloru
  • design_id
Podstawowe statystyki danych z tabeli
element_id part_num color_id design_id
Min. : 9327 Length:84138 Min. : -1.0 Min. : 1001
1st Qu.: 4259774 Class :character 1st Qu.: 8.0 1st Qu.: 18454
Median : 6057754 Mode :character Median : 28.0 Median : 41748
Mean : 5222065 NA Mean : 539.7 Mean : 45570
3rd Qu.: 6262024 NA 3rd Qu.: 135.0 3rd Qu.: 75474
Max. :61532443 NA Max. :9999.0 Max. :107520
NA NA NA NA’s :23682
Kilka pierwszych elementów z tabeli
element_id part_num color_id design_id
6443403 2277c01pr0009 1 2277
6300211 67906c01 14 67908
4566309 2564 0 2564
4275423 53657 1004 53657
6194308 92926 71 28967
6229123 26561 4 26561
Data summary
Name elements
Number of rows 84138
Number of columns 4
_______________________
Column type frequency:
character 1
numeric 3
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
part_num 0 1 2 19 0 33765 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
element_id 0 1.00 5222065.12 1596842.63 9327 4259773.50 6057754 6262024.5 61532443 ▇▁▁▁▁
color_id 0 1.00 539.67 2044.86 -1 8.00 28 135.0 9999 ▇▁▁▁▁
design_id 23682 0.72 45569.87 30750.66 1001 18453.75 41748 75474.5 107520 ▇▆▅▅▃

4.7 Colors

Tabela colors zawiera informacje o oficjalnych kolorach klocków LEGO.
Tabela zawiera 263 rekordy.

Atrybuty w tej tabeli to:

  • id
  • name - nazwa koloru
  • rgb - kolor zapisany w formacie RGB
  • is_trans - zmienna typu bool, określająca czy kolor jest transparentny
Podstawowe statystyki danych z tabeli
id name rgb is_trans
Min. : -1.0 Length:263 Length:263 Length:263
1st Qu.: 83.0 Class :character Class :character Class :character
Median :1005.0 Mode :character Mode :character Mode :character
Mean : 651.4 NA NA NA
3rd Qu.:1070.5 NA NA NA
Max. :9999.0 NA NA NA
Kilka pierwszych elementów z tabeli
id name rgb is_trans
-1 [Unknown] 0033B2 f
0 Black 05131D f
1 Blue 0055BF f
2 Green 237841 f
3 Dark Turquoise 008F9B f
4 Red C91A09 f
Data summary
Name colors
Number of rows 263
Number of columns 4
_______________________
Column type frequency:
character 3
numeric 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
name 0 1 3 28 0 263 0
rgb 0 1 6 6 0 223 0
is_trans 0 1 1 1 0 2 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
id 0 1 651.38 750.55 -1 83 1005 1070.5 9999 ▇▁▁▁▁

4.8 Inventory Minifigs

W tej tabeli zawarte zostały informacje o zapasach (nakładzie) figurek LEGO.
Tabela zawiera 20858 rekordów.

Atrybuty w tej tabeli to:

  • inventory_id
  • fig_num - oznaczenie figurki
  • quantity - ilość
Podstawowe statystyki danych z tabeli
inventory_id fig_num quantity
Min. : 3 Length:20858 Min. : 1.000
1st Qu.: 7869 Class :character 1st Qu.: 1.000
Median : 15681 Mode :character Median : 1.000
Mean : 43010 NA Mean : 1.062
3rd Qu.: 66834 NA 3rd Qu.: 1.000
Max. :194312 NA Max. :100.000
Kilka pierwszych elementów z tabeli
inventory_id fig_num quantity
3 fig-001549 1
4 fig-000764 1
19 fig-000555 1
25 fig-000574 1
26 fig-000842 1
26 fig-008641 1
Data summary
Name inventory_minifigs
Number of rows 20858
Number of columns 3
_______________________
Column type frequency:
character 1
numeric 2
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
fig_num 0 1 10 10 0 13455 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
inventory_id 0 1 43010.44 52256.78 3 7869 15681 66834 194312 ▇▁▁▁▁
quantity 0 1 1.06 0.78 1 1 1 1 100 ▇▁▁▁▁

4.9 Minifigs

W tabela minifigs znajdują się informacje o figurkach LEGO.
Tabela zawiera 13764 rekordy.

Atrybuty w tej tabeli to:

  • fig_num - numer figurki
  • name - nazwa figurki
  • num_parts - liczba części
  • img_url - adres url zdjęcia figurki
Podstawowe statystyki danych z tabeli
fig_num name num_parts img_url
Length:13764 Length:13764 Min. : 0.000 Length:13764
Class :character Class :character 1st Qu.: 4.000 Class :character
Mode :character Mode :character Median : 4.000 Mode :character
NA NA Mean : 5.296 NA
NA NA 3rd Qu.: 5.000 NA
NA NA Max. :156.000 NA
Kilka pierwszych elementów z tabeli
fig_num name num_parts img_url
fig-000001 Toy Store Employee 4 https://cdn.rebrickable.com/media/sets/fig-000001.jpg
fig-000002 Customer Kid 4 https://cdn.rebrickable.com/media/sets/fig-000002.jpg
fig-000003 Assassin Droid, White 8 https://cdn.rebrickable.com/media/sets/fig-000003.jpg
fig-000004 Man, White Torso, Black Legs, Brown Hair 4 https://cdn.rebrickable.com/media/sets/fig-000004.jpg
fig-000005 Captain America with Short Legs 3 https://cdn.rebrickable.com/media/sets/fig-000005.jpg
fig-000006 Lloyd Avatar 5 https://cdn.rebrickable.com/media/sets/fig-000006.jpg
Data summary
Name minifigs
Number of rows 13764
Number of columns 4
_______________________
Column type frequency:
character 3
numeric 1
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
fig_num 0 1 10 10 0 13764 0
name 0 1 1 148 0 13354 0
img_url 0 1 53 53 0 13764 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
num_parts 0 1 5.3 6.03 0 4 4 5 156 ▇▁▁▁▁

4.10 Inventory Sets

Tabela inventory_sets zawiera informacje o zapasach (nakładzie) zestawów LEGO.
Tabela zawiera 4358 rekordów.

Atrybuty w tej tabeli to:

  • inventory_id
  • set_num - oznaczenie zestawu
  • quantity - liczba
Podstawowe statystyki danych z tabeli
inventory_id set_num quantity
Min. : 35 Length:4358 Min. : 1.000
1st Qu.: 8076 Class :character 1st Qu.: 1.000
Median : 16423 Mode :character Median : 1.000
Mean : 52519 NA Mean : 1.813
3rd Qu.: 98685 NA 3rd Qu.: 1.000
Max. :191576 NA Max. :60.000
Kilka pierwszych elementów z tabeli
inventory_id set_num quantity
35 75911-1 1
35 75912-1 1
39 75048-1 1
39 75053-1 1
50 4515-1 1
50 4520-1 2
Data summary
Name inventory_sets
Number of rows 4358
Number of columns 3
_______________________
Column type frequency:
character 1
numeric 2
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
set_num 0 1 5 20 0 3171 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
inventory_id 0 1 52518.95 59063.13 35 8076 16423 98685 191576 ▇▁▁▂▁
quantity 0 1 1.81 5.67 1 1 1 1 60 ▇▁▁▁▁

4.11 Sets

Tabela sets zawiera informacje o oficjalnych kolorach klocków LEGO.
Tabela zawiera 21880 rekordów.

Atrybuty w tej tabeli to:

  • set_num - oznaczenie zestawu
  • name - nazwa zestawu
  • year - rok, z którego pochodzi zestaw
  • theme_id - numer kategorii zestawu
  • num_parts - liczba części
  • img_url - adres url zdjęcia zestawu
Podstawowe statystyki danych z tabeli
set_num name year theme_id num_parts img_url
Length:21880 Length:21880 Min. :1949 Min. : 1 Min. : 0.0 Length:21880
Class :character Class :character 1st Qu.:2001 1st Qu.:273 1st Qu.: 3.0 Class :character
Mode :character Mode :character Median :2012 Median :497 Median : 31.0 Mode :character
NA NA Mean :2008 Mean :442 Mean : 161.4 NA
NA NA 3rd Qu.:2018 3rd Qu.:608 3rd Qu.: 139.0 NA
NA NA Max. :2024 Max. :752 Max. :11695.0 NA
Kilka pierwszych elementów z tabeli
set_num name year theme_id num_parts img_url
001-1 Gears 1965 1 43 https://cdn.rebrickable.com/media/sets/001-1.jpg
0011-2 Town Mini-Figures 1979 67 12 https://cdn.rebrickable.com/media/sets/0011-2.jpg
0011-3 Castle 2 for 1 Bonus Offer 1987 199 0 https://cdn.rebrickable.com/media/sets/0011-3.jpg
0012-1 Space Mini-Figures 1979 143 12 https://cdn.rebrickable.com/media/sets/0012-1.jpg
0013-1 Space Mini-Figures 1979 143 12 https://cdn.rebrickable.com/media/sets/0013-1.jpg
0014-1 Space Mini-Figures 1979 143 2 https://cdn.rebrickable.com/media/sets/0014-1.jpg
Data summary
Name sets
Number of rows 21880
Number of columns 6
_______________________
Column type frequency:
character 3
numeric 3
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
set_num 0 1 3 20 0 21880 0
name 0 1 2 93 0 18752 0
img_url 0 1 46 63 0 21880 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
year 0 1 2007.76 13.96 1949 2001 2012 2018 2024 ▁▁▁▃▇
theme_id 0 1 441.97 215.53 1 273 497 608 752 ▃▃▃▇▇
num_parts 0 1 161.38 418.14 0 3 31 139 11695 ▇▁▁▁▁

4.12 Themes

W tej tabeli zawarte zostały informacje o oryginalnych kategoriach (tematykach) zestawów, jak i o współpracach np. (Lego Star Wars).
Tabela zawiera 468 rekordów.

Atrybuty w tej tabeli to:

  • id
  • name - nazwa kategorii (tematyki)
  • parent_id - numer kategorii “rodzica”
Podstawowe statystyki danych z tabeli
id name parent_id
Min. : 1.0 Length:468 Min. : 1.0
1st Qu.:250.5 Class :character 1st Qu.:186.0
Median :466.0 Mode :character Median :411.0
Mean :433.5 NA Mean :360.6
3rd Qu.:625.2 NA 3rd Qu.:512.5
Max. :752.0 NA Max. :697.0
NA NA NA’s :145
Kilka pierwszych elementów z tabeli
id name parent_id
1 Technic NA
3 Competition 1
4 Expert Builder 1
16 RoboRiders 1
17 Speed Slammers 1
18 Star Wars 1
Data summary
Name themes
Number of rows 468
Number of columns 3
_______________________
Column type frequency:
character 1
numeric 2
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
name 0 1 2 42 0 385 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
id 0 1.00 433.46 216.55 1 250.5 466 625.25 752 ▅▅▅▆▇
parent_id 145 0.69 360.64 197.19 1 186.0 411 512.50 697 ▅▃▂▇▂

5 Analiza danych

W tej sekcji dokonano analizy wczytanych danych w celu wykrycia ciekawych zależności oraz znalezienia pojawiających się na przestrzeni lat trendów dotyczących klocków LEGO.

5.1 Ogólna analiza

5.1.1 Najpopularniejsze figurki w zestawach

Poniższy wykres przedstawia 10 najczęściej występujących figurek w zestawach LEGO.

inventory_minifigs %>%
  merge(inventories, by.x="inventory_id", by.y="id") %>%
  merge(minifigs, by="fig_num") %>%
  group_by(fig_num, name) %>%
  summarize(fig_count = n()) %>%
  arrange(desc(fig_count)) %>%
  mutate(name = strtrim(name, 20)) %>%
  head(10) %>%
  ggplot(aes(x = reorder(name, fig_count), y = fig_count)) + 
           geom_bar(stat="identity", fill="#00abff") +
           coord_flip() + 
           ggtitle("10 najpopularniejszych figurek") +
           labs(x = "Figurka", y = "Liczba zestawów, w których występuje figurka") +
           theme_bw() + 
           easy_center_title() -> pop_fig
  
ggplotly(pop_fig)

Z wykresu wynika, że najbardziej popularną figurką jest figurka szkieleta, która występuje w 43 zestawach.

5.1.2 Rozkład materiałów, z których wykonano części

Poniżej znajduje się wykres kołowy oraz tabela podsumowująca procentowy rozkład materiałów, z których wykonano części LEGO. Niemalże wszystkie z nich (aż około 98,88%) zostały wykonane z plastiku. Następnym najczęściej używanym materiałem jest guma (około 0.71%).

parts %>%
  merge(inventory_parts, by="part_num") %>%
  group_by(part_material) %>%
  summarize(material_count = n()) %>%
  arrange(desc(material_count)) %>%
  mutate(prop = material_count / sum(material_count)) -> parts_by_material

parts_by_material %>%
  mutate(ypos = cumsum(prop) - 0.5 * prop) %>%
  ggplot(aes(x="", y=prop, fill=part_material)) +
  geom_bar(stat="identity", width=1, color="white") +
  coord_polar("y", start=0) +
  theme_void()

parts_by_material %>%
  mutate(prop = percent(prop)) %>%
  kable(col.names = c("Materiał", "Liczba części", "Procent"))
Materiał Liczba części Procent
Plastic 1167738 98.8781%
Rubber 8440 0.7147%
Cardboard/Paper 2367 0.2004%
Cloth 2029 0.1718%
Flexible Plastic 245 0.0207%
Metal 101 0.0086%
Foam 67 0.0057%

5.1.3 Najbardziej popularne tematyki zestawów

Poniżej znajduje się wykres przedstawiający 10 tematyk (motywów), w których jest najwięcej zestawów.

themes %>%
  rename(theme_name = name) %>%
  merge(sets, by.x="id", by.y="theme_id") %>%
  group_by(theme_name) %>%
  summarize(theme_count = n()) %>%
  arrange(desc(theme_count)) %>%
  head(10) %>%
  ggplot(aes(x = reorder(theme_name, theme_count), y = theme_count)) + 
           geom_bar(stat="identity", fill="#00abff") +
           coord_flip() + 
           scale_y_continuous(labels = label_comma()) +
           ggtitle("10 najpopularniejszych kategorii zestawów") +
           labs(x = "Kategoria zestawu", y = "Liczba zestawów w danej kategorii") +
           theme_bw() + 
           easy_center_title() -> pop_themes
  
ggplotly(pop_themes)

Z powyższego wykresu wynika, że najpopularniejszą tematyką (motywem) są Books, gdyż w tej kategorii są 973 zestawy.

5.1.4 Największe zestawy

Następna analiza dotyczy wielkości zestawów w zbiorze danych. Poniżej znajduje się wykres i tabela prezentująca 10 najbardziej złożonych zestawów LEGO ze zbioru Rebrickable.

sets %>%
  arrange(desc(num_parts)) %>%
  select(name, img_url, num_parts) %>%
  mutate(img_url = paste0("<","img src=",img_url," height=120 width=100>")) %>%
  head(10) -> big_sets

big_sets %>%
  ggplot(aes(x = reorder(name, num_parts), y = num_parts)) +
  geom_bar(stat="identity", fill="#00abff") +
  coord_flip() +
  scale_y_continuous(labels = label_comma()) +
  ggtitle("10 największych zestawów") +
  labs(x = "Zestaw", y = "Liczba części w zestawie") +
  theme_bw() +
  easy_center_title() -> big_sets_fig

ggplotly(big_sets_fig)
kable(big_sets, col.names = c("Nazwa", "", "Liczba części"), align = "c")
Nazwa Liczba części
World Map 11695
Eiffel Tower 10001
The Ultimate Battle for Chima 9987
Titanic 9092
Colosseum 9036
Millennium Falcon 7541
AT-AT 6785
The Razor Crest 6194
Lord of the Rings: Rivendell 6182
NINJAGO City Markets 6163

Największym zestawem LEGO w podanym zbiorze danych jest World Map, który składa się z dokładnie 11695 części.

5.1.5 Najpopularniejsze kolory części

W podanym zbiorze danym warto również było dokonać analizy popularności kolorów. Poniżej znajduje się wykres przedstawiający 10 najpopularniejszych kolorów części.

colors %>%
  rename(color_name = name) %>%
  merge(elements, by.x="id", by.y="color_id") %>%
  merge(parts, by.x="part_num", by.y="part_num") %>%
  group_by(rgb, color_name) %>%
  summarize(color_count = n()) %>%
  arrange(desc(color_count)) %>%
  mutate(rgb = paste0("#",rgb)) %>%
  head(10) %>%
  ggplot(aes(x = reorder(color_name, color_count), y = color_count, fill=rgb, color="black")) + 
           geom_bar(stat="identity") +
           coord_flip() + 
           scale_fill_identity() +
           scale_color_identity() +
           scale_y_continuous(labels = label_comma()) +
           ggtitle("10 najpopularniejszych kolorów części") +
           labs(x = "Kolor", y = "Liczba części") +
           theme_bw() +  theme(legend.position = "none") +
           easy_center_title() -> pop_color
  
ggplotly(pop_color)

Z powyższego wykresu wynika, że najpopularniejeszymi kolorami części LEGO są czarny i biały.

5.1.6 Najpopularniejsze kategorie (rodzaje) części

Poniżej znajduje się wykres przedstawiający 10 najczęściej występujących kategorii (rodzajów) części.

parts %>%
  rename(part_name = name) %>%
  merge(part_categories, by.x="part_cat_id", by.y="id") %>%
  group_by(part_cat_id, name) %>%
  summarize(part_count = n()) %>%
  arrange(desc(part_count)) %>%
  head(10) %>%
  ggplot(aes(x = reorder(name, part_count), y = part_count)) +
  geom_bar(stat="identity", fill="#00abff") +
  coord_flip() +
  scale_y_continuous(labels = label_comma()) +
  ggtitle("10 najpopularniejszych kategorii części") +
  labs(x = "Kategoria", y = "Liczba części należących do kategorii") +
  theme_bw() +
  easy_center_title() -> pop_cat_fig
  
ggplotly(pop_cat_fig)

Z powyższego wykresu wynika, że najliczniejszą kategorią jest Minifig Upper Body, do której należy 6329 części.

5.1.7 Najpopularniejsze części w zestawach

Kolejna analiza dotyczy popularności części w zestawach (biorąc pod uwagę również kolor). Poniżej znajduje się wykres oraz tabela przedstawiająca 10 najpopularniejszych części w zestawach LEGO.

parts %>%
  merge(inventory_parts, by.x="part_num", by.y="part_num") %>%
  merge(inventories, by.x="inventory_id", by.y="id") %>%
  group_by(part_num, name, img_url, color_id) %>%
  summarize(part_count = n()) %>%
  mutate(img_url = paste0("<","img src=",img_url," height=100 width=100>")) %>%
  select(part_num, name, img_url, part_count, color_id) %>%
  arrange(desc(part_count)) %>%
  head(10) -> pop_parts

pop_parts %>%
  mutate(name = strtrim(name, 20)) %>%
  ggplot(aes(x = reorder(paste0(part_num, ": ", name, " (", color_id, ")"), part_count), y = part_count, fill=)) + 
           geom_bar(stat="identity", fill="#00abff") +
           coord_flip() + 
           scale_color_identity() +
           scale_y_continuous(labels = label_comma()) +
           ggtitle("10 najpopularniejszych części w zestawach") +
           labs(x = "Część", y = "Liczba wystąpięń części") +
           theme_bw() +
           easy_center_title() -> pop_parts_fig
  
ggplotly(pop_parts_fig)
pop_parts %>%
  select(part_num, name, img_url, part_count) %>%
  kable(col.names = c("Nr części", "Nazwa części", "", "Łączna liczba wystąpień części"), align = "c")
Nr części Nazwa części Łączna liczba wystąpień części
2780 Technic Pin with Friction Ridges Lengthwise and Center Slots 4769
6141 Plate Round 1 x 1 with Solid Stud 2922
3023 Plate 1 x 2 2630
6141 Plate Round 1 x 1 with Solid Stud 2371
3673 Technic Pin without Friction Ridges Lengthwise 2312
43093 Technic Axle Pin with Friction Ridges Lengthwise 2264
3023 Plate 1 x 2 2256
4274 Technic Pin 1/2 2237
3022 Plate 2 x 2 2098
3020 Plate 2 x 4 2092

Najczęściej występującą częścią w zestawach jest Technic Pin with Friction Ridges Lengthwise and Center Slots, który znalazł sie łącznie 4769 razy we wszystkich zestawach LEGO.

5.1.8 Transparentość części

Dokonano również analizy dotyczącej transparentności kolorów części. Poniżej znajduje sie wykres oraz tabela przedstawiająca, ile części jest w kolorze transparentnym i nietransparentnym.

parts %>%
  merge(elements, by="part_num") %>%
  merge(colors, by.x="color_id", by.y="id") %>%
  group_by(is_trans) %>%
  summarize(trans_count = n()) %>%
  mutate(trans_count_prop = percent(trans_count / sum(trans_count))) %>%
  mutate(is_trans = recode(is_trans, "f" = "Nie", "t" = "Tak")) -> trans_parts

trans_parts %>%
  ggplot(aes(x = is_trans, y = trans_count), fill = factor(trans_count_prop)) +
  geom_bar(stat="identity", position="identity", fill="#00abff") +
  scale_y_continuous(labels = label_comma()) +
  ggtitle("Transparentność części") +
  labs(x = "Czy część jest transparentna?", y = "Liczba części") +
  theme_bw() +
  easy_center_title() -> trans_parts_fig
  
ggplotly(trans_parts_fig)
trans_parts %>%
  select(is_trans, trans_count, trans_count_prop) %>%
  kable(col.names = c("Transparentność", "Liczba części", "[%]"), align = "c")
Transparentność Liczba części [%]
Nie 78966 94%
Tak 5172 6%

Na podstawie wykresu i tabeli można stwierdzić, że zdecydowana większość (94%) części jest w kolorze nietransparentnym.

5.1.9 Najbardziej złożone tematyki (motywy)

Następna analiza ma na celu znalezienie najbardziej złożonych tematyk (motywów) tj. takich, w których skład wchodzą inne tematyki (motywy). Poniżej znajduje się wykres przedstawiający 10 motywów z największą liczbą podmotywów.

themes %>%
  rename(theme_name = name) %>%
  merge(themes, by.x="id", by.y="parent_id") %>%
  group_by(theme_name) %>%
  summarize(complex_theme_count = n()) %>%
  arrange(desc(complex_theme_count)) %>%
  head(10) %>%
  ggplot(aes(x = reorder(theme_name, complex_theme_count), y = complex_theme_count)) +
  geom_bar(stat="identity", fill="#00abff") +
  scale_y_continuous(labels = label_comma()) +
  coord_flip() +
  ggtitle("10 najbardziej złożonych motywów") +
  labs(x = "Tematyka", y = "Liczba podmotywów") +
  theme_bw() +
  easy_center_title() -> comp_themes_fig
  
ggplotly(comp_themes_fig)

5.2 Analiza trendów

W tej sekcji dokonano analizy zmian związanych z LEGO, jakie zachodziły na przestrzeni lat.

5.2.1 Tematyki zestawów

Poniżej znajduje się wykres pokazujący jak zmieniała się liczba nowych tematyk na przestrzeni lat (1949-2023).

themes %>%
  rename(theme_name = name) %>%
  merge(sets, by.x="id", by.y="theme_id") %>%
  filter(year <= 2023) %>%
  group_by(year) %>%
  summarize(new_themes_count = n_distinct(theme_name, na.rm = T)) -> unique_themes

unique_themes %>%
  ggplot(aes(x = year, y = new_themes_count)) +
  geom_line(color="#00abff") +
  ggtitle("Nowe tematyki na przestrzeni lat") +
  labs(x = "Rok", y = "Liczba tematyk") +
  theme_bw() +
  theme(legend.position = "none") +
  easy_center_title() -> new_themes_trend_fig
  
ggplotly(new_themes_trend_fig)

5.2.2 Części w zestawach

Kolejna analiza dotyczy średniej liczby części wchodzącej w skład zestawów na przestrzeni lat (1949-2023).

sets %>%
  filter(year <= 2023) %>%
  group_by(year) %>%
  summarize(set_mean_parts = mean(num_parts, na.rm = T), sets_count = n()) -> mean_parts

mean_parts %>%
  ggplot(aes(x = year, y = set_mean_parts)) +
  geom_line(color="#00abff") +
  ggtitle("Średnia liczba części w zestawach na przestrzeni lat") +
  labs(x = "Rok", y = "Średnia liczba części") +
  theme_bw() +
  theme(legend.position = "none") +
  easy_center_title() -> mean_parts_per_set_trend_fig
  
ggplotly(mean_parts_per_set_trend_fig)

5.2.3 Figurki w zestawach

Poniżej znajduje się wykres przedstawiający wykorzystanie figurek w zestawach. Pierwsze figurki LEGO pojawiły się w 1975 roku.

minifigs %>%
  rename(fig_name = name, fig_num_parts = num_parts) %>%
  merge(inventory_minifigs, by.x="fig_num", by.y="fig_num") %>%
  merge(inventories, by.x="inventory_id", by.y="id") %>%
  merge(sets, by.x="set_num", by.y="set_num") %>%
  filter(year <= 2023) %>%
  group_by(year) %>%
  summarize(figures_count = n()) -> minifigs_trend

minifigs_trend %>%
  ggplot(aes(x = year, y = figures_count)) +
  geom_line(color="#00abff") +
  ggtitle("Łączna liczba figurek wykorzystanych w zestawach w latach 1975-2023") +
  labs(x = "Rok", y = "Liczba figurek") +
  theme_bw() +
  theme(legend.position = "none") +
  easy_center_title() -> fig_usage_trend_fig
  
ggplotly(fig_usage_trend_fig)

5.2.4 Zestawy na przestrzeni lat

W tej sekcji przeanalizowano liczbę zestawów pojawiających się na przestrzeni lat.

sets %>%
  filter(year <= 2023) %>%
  group_by(year) %>%
  summarize(sets_count = n()) %>%
  ggplot(aes(x = year, y = sets_count)) +
  geom_line(color="#00abff") +
  ggtitle("Liczba wydanych zestawów na przestrzeni lat") +
  labs(x = "Rok", y = "Liczba zestawów") +
  theme_bw() +
  theme(legend.position = "none") +
  easy_center_title() -> sets_trend_fig
  
ggplotly(sets_trend_fig)

5.2.5 Liczba elementów w części

Poniżej znajduje się wykres pokazujący jak na przestrzeni lat zmieniała się średnia liczba elementów w jednej części.

elements %>%
  group_by(part_num, color_id) %>%
  summarize(elem_per_part = n()) -> element_count

inventory_parts %>%
  rename(part_quantity = quantity) %>%
  merge(parts, by.x="part_num", by.y="part_num") %>%
  rename(part_name = name) %>%
  merge(colors, by.x="color_id", by.y="id") %>%
  rename(color_name = name) %>%
  merge(part_categories, by.x="part_cat_id", by.y="id") %>%
  rename(part_cat_name = name) %>%
  merge(element_count, by = c("part_num", "color_id")) %>%
  merge(inventories, by.x="inventory_id", by.y="id") %>%
  merge(sets, by.x="set_num", by.y="set_num") %>%
  filter(year <= 2023) %>%
  group_by(year) %>%
  summarize(mean_elements_per_part = mean(elem_per_part, na.rm=T)) -> mean_elements_count

mean_elements_count %>%
  ggplot(aes(x = year, y = mean_elements_per_part)) +
    geom_line(color="#00abff") +
    ggtitle("Średnia liczba elementów w jednej części na przestrzeni lat") +
    labs(x = "Rok", y = "Średnia liczba elementów w jednej części") +
    theme_bw() +
    theme(legend.position = "none") +
    easy_center_title() -> mean_elem_fig

ggplotly(mean_elem_fig)

6 Korelacja między atrybutami

Poniżej znajduje się wykres przedstawiający korelację pomiędzy poszczególnymi parametrami w zbiorze.

unique_themes %>%
  merge(mean_parts) %>%
  merge(minifigs_trend) %>%
  merge(trans_parts) %>%
  merge(mean_elements_count) %>%
  select(year, new_themes_count, set_mean_parts, sets_count, figures_count, mean_elements_per_part) -> dataset
  
correlation <- cor(dataset)
ggcorrplot(correlation)

kable(correlation)
year new_themes_count set_mean_parts sets_count figures_count mean_elements_per_part
year 1.0000000 0.9582409 0.7233515 0.9387636 0.9142305 0.5046801
new_themes_count 0.9582409 1.0000000 0.6550353 0.9503790 0.9135261 0.4704375
set_mean_parts 0.7233515 0.6550353 1.0000000 0.6887085 0.7524310 0.0024544
sets_count 0.9387636 0.9503790 0.6887085 1.0000000 0.9700925 0.3025752
figures_count 0.9142305 0.9135261 0.7524310 0.9700925 1.0000000 0.2265509
mean_elements_per_part 0.5046801 0.4704375 0.0024544 0.3025752 0.2265509 1.0000000

7 Predykcja dalszych cech zestawów LEGO